<%@ page language="java" pageEncoding="UTF-8" %>
<%@ page import="com.ncr.teradata.bireport.*" %>
<%@ page import="java.util.List" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="com.telecom.cms.dto.SysUser" %>
<%
	String cityCode = "";
	String countryCode = "";
	
	String campId = "";
	String campSeqId = "";
	String dateId = "";
	String contRsltId = "";
	Enumeration e = request.getParameterNames();
	while (e.hasMoreElements())
	{
		String hdName = (String)e.nextElement();
		if (hdName.equals("campId"))
			campId = request.getParameter(hdName);
		if (hdName.equals("campSeqId"))
			campSeqId = request.getParameter(hdName);
		if (hdName.equals("dateId"))
			dateId = request.getParameter(hdName);
		if (hdName.equals("contRsltId"))
			contRsltId = request.getParameter(hdName);
	}
	
	Report report = new Report("CAMP_CONT_RSLT",cityCode,countryCode);
	SysUser user = (SysUser)request.getSession().getAttribute("User_Inst");
	if (user.getUserRole().equals("1"))
		report.addFilter("Team_Id",new String[]{String.valueOf(user.getTeamId())});
	if (user.getUserRole().equals("2"))
		report.addFilter("User_Id",new String[]{String.valueOf(user.getUserId())});
	if(!campId.equals(""))
		report.addFilter("Camp_Id",new String[]{campId});
	if(!campSeqId.equals(""))
		report.addFilter("Camp_Seq_Id",new String[]{campSeqId});
	if(!contRsltId.equals(""))
		report.addFilter("Camp_Cont_Rslt_Lvl1_Id",new String[]{contRsltId});
	if(dateId.equals(""))
		dateId = (String)report.getDimensionMaxValue("Date_Id");
	report.addFilter("Date_Id",new String[]{dateId});
	
	report.addDimension(new String[]{"User_Name"});
	report.addMeasure(new String[]{"Rslt_Count"});
	report.addSubtotal(Report.BOTTOM);
	//String tableStr = report.buildTableData();
	List reportData2 = report.buildData();
	
	Object[] campIds = report.getDimensionValues("Camp_Id");
	Object[] campSeqIds = report.getDimensionValues("Camp_Seq_Id","Camp_Id",campId);
	Object[] dateIds = report.getDimensionValues("Date_Id");
	Object[] contRsltIds = report.getDimensionValues("Camp_Cont_Rslt_Lvl1_Id");
%>

<html>
<head>
	<title>接触结果日分析</title>
	<link href="../css/style.css" rel="stylesheet" type="text/css"/>
    <link href="../css/font.css" rel="stylesheet" type="text/css">
<SCRIPT>
	function campIdChg(campId){
		document.location.href = "camp_audit_cont_detail.jsp?campId=" + campId;
	}

	function submitForm(){
		form1.submit();
	}
	
	function exportData(spanId,fileName)
	{
	
		document.all.exportFileName.value = fileName+".xls";
	    exportExcel(document.getElementById(spanId).innerHTML,'../export');
		document.all.exportFileName.value=fileName;
	}
	
	function exportExcel(s,URL)
	{	
	    var oldAction=document.forms[0].action; 
		document.forms[0].exportContent.value="<META content=text/html; charset=GBK http-equiv=Content-Type/>"+s;
		document.forms[0].action=URL;
		document.forms[0].submit();	
		document.forms[0].action = oldAction;
	}
</SCRIPT>
</head>
<body>
<form name="form1" method="post" action="camp_audit_cont_detail.jsp">
	<input type="hidden" name="exportFileName" value="" />
	<input type="hidden" name="exportContent"  value="" />
	<table width="95%" height="100%"  border="0" align="center" cellpadding="0" cellspacing="1" >
		<tr>
			<td valign='top' align='left' bgcolor="#FFFFFF"> 
				<table border=0 width="100%" class="tablestyle4" style='table-layout:' cellspacing='2' cellpadding='2' bordercolordark='#ffffff' bordercolorlight='#ffffff'>
					<tr class="fontblue" width="100%" align="left">
						<td><img src="../images/title_left.gif" width="10" height="10"></td>
						<td align='left' valign='center'>
                    		接触结果分析：
                    	</td>
                    	<td align='left' valign='top'>
							营销活动：
                        	<select class="select" name="campId" style='width:100' onchange="campIdChg(this.value);">
								<option value="" <% if(campId.equals("")) out.print("selected"); %>>全部</option>
								<% for(int i = 0; i < campIds.length; i++){ %>
	    	                		<OPTION value="<%= (String)campIds[i] %>" <% if(((String)campIds[i]).equals(campId)) out.print("selected"); %>><%= report.getNameValueByID("Camp_Id","Camp_Name",(String)campIds[i]) %></OPTION>
	    	                	<% } %>
	    	            	</select>
                        </td>
						<td align='left' valign='top'>
							营销批次：
                        	<select class="select" name="campSeqId" style='width:120' onchange="submitForm();">
								<option value="" <% if(campSeqId.equals("")) out.print("selected"); %>>全部</option>
	    	                	<% for(int i = 0; i < campSeqIds.length; i++){ %>
	    	                		<OPTION value="<%= (String)campSeqIds[i] %>" <% if(((String)campSeqIds[i]).equals(campSeqId)) out.print("selected"); %>><%= report.getNameValueByID("Camp_Seq_Id","Camp_Seq_Name",(String)campSeqIds[i]) %></OPTION>
	    	                	<% } %>
	    	            	</select>
                        </td>
                        <td align='left' valign='top'>
                    		日期：
                        	<select class="select" name="dateId" style='width:100' onchange="submitForm();">
	    	                	<% for(int i = dateIds.length - 1; i >= 0; i--){ %>
	    	                		<OPTION value="<%= (String)dateIds[i] %>" <% if(((String)dateIds[i]).equals(dateId)) out.print("selected"); %>><%= (String)dateIds[i] %></OPTION>
	    	                	<% } %>
	    	            	</select>
                        </td>
                        <td align='left' valign='top'>
                    		接触结果：
	    	            	<select class="select" name="contRsltId" style='width:120' onchange="submitForm();">
								<option value="" <% if(contRsltId.equals("")) out.print("selected"); %>>全部</option>
	    	                	<% for(int i = 0; i < contRsltIds.length; i++){ %>
	    	                		<OPTION value="<%= (String)contRsltIds[i] %>" <% if(((String)contRsltIds[i]).equals(contRsltId)) out.print("selected"); %>><%= report.getNameValueByID("Camp_Cont_Rslt_Lvl1_Id","Camp_Cont_Rslt_Lvl1_Name",(String)contRsltIds[i]) %></OPTION>
	    	                	<% } %>
	    	            	</select>
                        </td>
                        <td align="right" valign='center'>
                    		<img name="btnSubmit" src="../images/button_export.gif" width="63" height="21" onclick="exportData('spanId1','Export data');" class="box_button">
                    	</td>
                        <td align="right" valign='center' width='10%'>
                        	&nbsp;
                        </td>
					</tr>
				</table>
				<span id="spanId1">
				<table border=1 width="50%" class="tablestyle1" style='table-layout:fixed' cellspacing='0' cellpadding='0' bordercolordark='#ccffff' bordercolorlight='#9999cc'>
					<tr align="center">
						<td>外呼人员名称</td>
						<td>用户数</td>
					</tr>
					<%
						for(int i = 0; i < reportData2.size(); i++) {
							Object[] row = (Object[])reportData2.get(i); 
					%>
					<tr align="right">
						<TD align="center"><%= (i == reportData2.size() - 1 ? "小计" : (String)row[0]) %></a></TD>
						<TD><%= (BigDecimal)row[1] %></TD>
					</tr>
					<% } %>
				</table>
				</span>
				<%//= tableStr %>
			</td>
		</tr>
	</table>
</form>
</body>
</html>


